var dateFormat={
    /* 获取当前时间
    *使用方法2
    * document.write("格式1：" + dateFormat.format("yyyy年MM月dd日"));
     document.write("格式2：" + dateFormat.format("yyyy年MM月dd日hh小时mm分ss秒"));
     document.write("格式3：" + dateFormat.format("yy年MM月dd日"));
     document.write("格式4：" + dateFormat.format("MM月dd日hh小时mm分ss秒"));
     document.write("格式5：" + dateFormat.format("yyyy/MM/dd"));
     document.write("格式6：" + dateFormat.format("yyyy/MM/dd hh/mm/ss"));
     document.write("格式7：" + dateFormat.format("yyyy-MM-dd"));
     document.write("格式8：" + dateFormat.format("yyyy-MM-dd hh-mm-ss"));
     document.write("格式9：" + dateFormat.format("yyyy:MM:dd"));
     document.write("格式10：" + dateFormat.format("yyyy:MM:dd hh:mm:ss"));
     document.write("格式11：" + dateFormat.format("yyyy/MM/dd hh:mm:ss"));
     document.write("格式12：" + dateFormat.format("yyyy-MM-dd hh:mm:ss"));
     document.write("格式13：" + dateFormat.format("yy-MM-dd hh:mm:ss"));
     document.write("格式14：" + dateFormat.format("MM-dd hh:mm:ss"));
    *
    * */
    format: function (format) {
        var date=new Date();
        var format=format;
        var o = {
            "M+": date.getMonth() + 1, //month
            "d+": date.getDate(), //day
            "h+": date.getHours(), //hour
            "m+": date.getMinutes(), //minute
            "s+": date.getSeconds(), //second
            "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
            "S": date.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
            }
        }
        return format;
    },
    /* 时间戳转换 */
    formatDateTime: function (inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        //return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
        return y + '-' + m + '-' + d+' '+h+':'+minute;
    }

};

module.exports = dateFormat;


